<!DOCTYPE html>
<html>
<head>
	<meta charset="utf-8">
	<meta name="viewport" content="width=device-width, initial-scale=1">
	<title></title>
</head>
<body>
	<input type="file" name="">
	<img src="" alt="待上传">

	<script type="text/javascript">
		let inp = document.querySelector('input')
		let img = document.querySelector("img")

		inp.onchange = function() {
			console.log(inp.files)//上传图片信息

			//FormData 用来处理上传的文件 ,通常用来发送表单数据
			let fileParam = new FormData()
			//append 向FormData 里添加一个新的键值对 key: value
			fileParam.append("file", inp.files[0])


			let xhr = new XMLHttpRequest()
			xhr.open("post", "http://joint.byesame.com/upload")
			//不要加请求头
			xhr.send(fileParam)
			xhr.onreadystatechange = function(){
				if (xhr.readyState == 4) {
					let res = JSON.parse(xhr.responseText)
					console.log(res)
					//
					//
					let str = res.data.path.replace("http://localhost:3002", "http://joint.byesame.com")
					img.src = str
				}
			}
		}
	</script>
</body>
</html>